var t = getApp(), e = t.requirejs('core'), a = t.requirejs("foxui");
Page({
    data: {
        submit: !1,
        site: "请选择代理区域",
        log: [],
        haslog: 0
    },
    // 切换城市
    changSite(s) {
        this.setData({
            site: s.detail.value.join(" ")
        })
    },
    onShow(){
        e.get("yam/apply", {}, res => {
            console.log(res);
            if(res.areas){
                this.setData({
                    log: res.apply_log,
                    site: res.areas,
                    haslog: res.haslog
                })
            }else{
                this.setData({
                    log: res.apply_log,
                    haslog: res.haslog
                })
            }
        })
    },
    // 提交
    submit(s) {
        let data = s.detail.value;
        if (!this.data.submit) {
            if(!data.name) {
                wx.showToast({
                    title: '请输入姓名',
                    icon: 'none'
                })
                return
            }
            if(!data.mobile && data.mobile.length != 11) {
                wx.showToast({
                    title: '请输入正确的手机号',
                    icon: 'none'
                })
                return
            }
            if(!data.site.length) {
                wx.showToast({
                    title: '请选择地址',
                    icon: 'none'
                })
                return
            }

            data.province = data.site[0];
            data.city = data.site[1];
            data.area = data.site[2];
            console.log(data);
            e.get("yam/apply/submit", data, res => {
                console.log(res);
                0 == res.error ? (this.setData({
                    submit: !1
                }), a.toast(this, "修改成功"), setTimeout(function() {
                    wx.navigateBack();
                }, 500)) : a.toast(this, res.message);
            })
        }
    }
})